#pragma once

#include "AB_MoveUnit.h"
#include "PlayerUnit.h"
#include "Terrain.h"
#include "Camera.h"
#include "UnitManager.h"
#include <iostream>
namespace game
{
	class Counter
	{
		int _i;
	public :
		Counter()
		{
			_i = 0;
		}
		bool WaitFrames(int mod)
		{
			_i++;
			if (_i % mod == 0){return true;}
			else { return false;}
		}
		int get_time(){return _i;}
		~Counter(){}
	};


	class StatePlaying:public IGameState
	{
	public:
		bool				_loaded;

		//Managers//
		GameStateManager *		_gameStateManager;
		UnitManager *		_unitManager;
		Counter *			_counter;
		//PlayerUnit *		_ent;

		//ability::Ability_HurtSelf* abil_hurt_self;
		//ability::Ability_MoveUnit* abil_move_unit;
		ability::Ability_MoveToNearestUnit* a_move;

		StatePlaying(game::GameStateManager *gsm)
		{
			_unitManager = new UnitManager();
			_gameStateManager = gsm;
			_loaded =false;
			_counter = new Counter();
		}

		~StatePlaying()
		{
			delete _unitManager;
			/*delete _ent;*/
		}

		game::GameStateManager * getManager(){return _gameStateManager;}
		bool isTransparent(){return false;}

		bool isLoaded(){return _loaded;}

		void Load()	//Load Stuff Here
		{
			//load terrain map

			getManager()->getTerrainManager()->LoadRandomMap(32,32,2,1);
			_unitManager->Add(new PlayerUnit("lizard",sf::Vector2f(128,128),getManager()));
			_unitManager->Add(getManager()->get_unit_factory()->CreateUnit("slime",sf::Vector2f(365,253)));
			//_ent = new PlayerUnit("lizard",sf::Vector2f(128,128),getManager());
			a_move = new ability::Ability_MoveToNearestUnit(_unitManager->get_unit("slime"));
			a_move->selectTarget(_unitManager);
			a_move->use(0);
			//Ability Test

			//abil_move_unit = new ability::Ability_MoveUnit(_ent);
			//abil_move_unit->selectTarget(new sf::Vector2u(256,256));
			//abil_move_unit->use(1000);
			//abil_hurt_self = new ability::Ability_HurtSelf(_ent,1);
			//abil_hurt_self->use(1200);

			_loaded = true;
		}

		void Update()
		{
			//update entities
			_unitManager->Update();

			if (_counter->WaitFrames(200))
			a_move->use(_counter->get_time());

			//abil_hurt_self->use(1200);
			//_ent->Update();			
		}

		void Draw()
		{
			getManager()->getTerrainManager()->Draw();
			//_ent->Draw();
			_unitManager->Draw();
		}
	};
}